using GameFramework;
using GameFramework.Event;
using System;
using UnityGameFramework.Runtime;

namespace LS.Event
{
    public static class LSGameEventArgsExtension
    {
        private static EventComponent EventComponent = null;

        private static EventComponent GetEventComponent()
        {
            if (EventComponent == null)
            {
                EventComponent = UnityGameFramework.Runtime.GameEntry.GetComponent<EventComponent>();
            }
            return EventComponent;
        }
        /// <summary>
        /// 发送事件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sender"></param>
        public static void FireEvent<T>(this object sender)
            where T : LSGameEventArgs, IReference, new()
        {
            
            FireEvent<T>(sender, LSGameEventArgs.Create<T>());
        }

        /// <summary>
        /// 发送事件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sender"></param>
        /// <param name="dataParams"></param>
        public static void FireEvent<T>(this object sender, T args)
            where T : LSGameEventArgs, IReference, new()
        {
            GetEventComponent().Fire(sender, args);
        }

        /// <summary>
        /// 发送事件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sender"></param>
        public static void FireEventNow<T>(this object sender)
            where T : LSGameEventArgs, IReference, new()
        {
            var args = LSGameEventArgs.Create<T>();
            FireEventNow<T>(sender, args);
        }

        /// <summary>
        /// 发送事件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sender"></param>
        /// <param name="dataParams"></param>
        public static void FireEventNow<T>(this object sender, T args)
            where T : LSGameEventArgs, IReference, new()
        {
            GetEventComponent().Fire(sender, args);
        }
    }
}